<template>
  <div class="exhibit-top">
    <div class="ex-img-left">
      <div
        class="ex-img-parent"
        :style="{
          backgroundImage: `url(${
            publicUrls + 'free/style10/scrollBcakgroundExhibits10leftbg.png?imageView3/format/webp'
          })`,
        }"
      >
        <a class="Icon3d" target="blank" :href="props.info.externalUrl" v-if="props.info.externalUrl">
          <img :src="publicUrls + 'free/style10/style103dIcon777.png'" alt="" />
        </a>
        <div class="ex-img">
          <img
            class="cover"
            v-if="props.info.images?.length > 1"
            :src="$filters.getLinkUrl(props.info.images[current]?.data + '?imageView2/0/w/1000/format/webp')"
            alt=""
            @click="viewImg(props.info.images[current]?.data)"
          />
          <img
            class="cover"
            v-else
            :src="$filters.getLinkUrl(props.info.coverUrl + '?imageView2/0/w/1000/format/webp')"
            alt=""
            @click="viewImg(props.info.coverUrl)"
          />
        </div>
      </div>
      <div v-if="props.info.images?.length > 1" class="doot-parent">
        <div
          class="doot-box"
          :class="{ 'doot-anim': props.info.images?.length <= 4 }"
          @mousewheel="handlWheel"
          ref="doot"
        >
          <div
            :id="'dot-parents' + index"
            class="dot-parents"
            :class="{ 'dot-parents-warp': store.isMobileType, 'dot-parents-active': current === index }"
            v-for="(item, index) in props.info.images"
            :key="index"
          >
            <div
              class="dot-content"
              :class="{
                'dot-1': index === 0,
              }"
            >
              <div
                @click="setCurrent(index)"
                class="doot-item"
                :class="{ 'doot-item-active': current === index, 'item-mg': index === 0 }"
              >
                <div class="shadown">
                  <span v-if="item.type == -1">封面</span>
                  <span v-else-if="item.type == 1">正视图</span>
                  <span v-else-if="item.type == 2">俯视图</span>
                  <span v-else-if="item.type == 3">侧视图</span>
                  <span v-else-if="item.type == 4">全景图</span>
                  <span v-else-if="item.type == 5">局部图</span>
                  <span v-else-if="item.type == 6">底部图</span>
                  <span v-else>未设置</span>
                </div>
                <img :src="$filters.getLinkUrl(item.data + '?imageView2/1/w/160/h/160/format/webp')" alt="" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 右侧描述 -->
    <div class="exhibhts-desc">
      <div class="exhibits-parameter">
        <div
          class="right-heard"
          :style="{
            backgroundImage: `url(${
              publicUrls + 'free/style10/scrollBcakgroundExhibits10right.png?imageView3/format/webp'
            })`,
          }"
        >
          基本信息
        </div>
        <div class="parameter-item parameter-item-top">
          <div class="parameter-key">展品类型</div>

          <div class="parameter-name overflow">
            {{ props.info.typeValue || '-' }}
          </div>
        </div>
        <div class="parameter-item">
          <div class="parameter-key">展品级别</div>

          <div class="parameter-name">
            <span class="item-title2">{{ props.info.levelValue }}</span>
          </div>
        </div>
        <div class="parameter-item">
          <div class="parameter-key">展品来源</div>

          <div class="parameter-name overflow">
            {{ props.info.specificSources || '-' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">所属年代</div>

          <div class="parameter-name overflow">
            {{ props.info.concreteTimes ? props.info.concreteTimes : props.info.ageValue || '-' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">收藏单位</div>

          <div class="parameter-name overflow">{{ props.info.location ? props.info.location : info.companyName }}</div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">展品质地</div>

          <div class="parameter-name overflow">
            {{ props.info.texture || '-' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">展品尺寸</div>

          <div class="parameter-name">
            {{ props.info.size || '-' }}
          </div>
        </div>
      </div>
      <div class="btn" v-if="info.openStatus === 1 && !store.isMobileType">
        <t-tooltip content="将此展品添加到我的关注" v-if="info.openStatus === 1 && !store.isMobileType">
          <div class="add-btn1 myPostattention" @click="postattention">
            <i v-if="!info.isFollow" class="iconfonts">&#xe6aa;</i>
            <i v-else class="iconfonts">&#xe6a9;</i>
            <div class="myPostattention-text">收藏</div>
            <!-- {{ info.followTotal }} -->
          </div>
        </t-tooltip>
        <t-tooltip content="将此展品添加到我的展览" v-if="info.openStatus === 1 && !store.isMobileType">
          <div
            @click="addId"
            class="add-exhibition"
            :style="{
              backgroundImage: `url(${
                publicUrls + 'free/style10/scrollBcakgroundExhibits10addbg.png?imageView3/format/webp'
              })`,
            }"
          >
            <span class="iconfonts">&#xe6a7;</span>
            <span>添加至展览</span>
          </div>
        </t-tooltip>
      </div>
    </div>
    <!-- 添加展览弹窗 -->

    <!-- 是否登录 -->
    <messageModel
      submitText="前往"
      title="提示"
      :visible="visibleMessage"
      problem="您暂未登录"
      message="是否前往登录？"
      @closeClick="closeClick"
      @submitClick="pathSubmitClick"
      style="z-index: 999"
    />
  </div>
</template>

<script lang="ts">
export default defineComponent({
  name: 'exhibitsTop',
});
</script> 
  
<script setup lang="ts">
// @ts-nocheck
import { defineComponent, ref, computed, watch } from 'vue';
import { projectLists } from '@/api/project/project';
import { MessagePlugin } from 'tdesign-vue-next';
import { getHeardToken } from '@/api/utils';
import { addExhibits } from '@/api/desgin/desgin';
import { publicUrls } from '@/utils/minxin';
import { followSet } from '@/api/interact/interact';
import { useProjectStore } from '@/store';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { Action } from 'element-plus';

const visibleMessage = ref(false);
const selectInitList = ref();
const projectId = ref(null);
const current = ref(0);
const store = useProjectStore();
const loading = ref(false);
const doot = ref(null);
const visibleStep = ref(false);
const Scrollheights = ref();

let viewportHeight = window.innerHeight;
Scrollheights.value = viewportHeight * 0.5844;
const getScrollHeight = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 512;
  return heights + 'px';
});
const props = defineProps({
  info: {
    type: Object,
  },
});

const emits = defineEmits(['viewImg', 'addExId']);

const viewImg = (i: any) => {
  emits('viewImg', i, current.value);
};

// 添加关注事件
const postattention = async () => {
  let token = getHeardToken();
  if (!token) {
    store.loginModeShow = true;

    return;
  } else {
    try {
      let { data } = await followSet({ refType: 4, refId: props.info.id });
      props.info.isFollow = data;
      if (props.info.isFollow) {
        props.info.followTotal = props.info.followTotal + 1;
        MessagePlugin.success('关注成功');
      } else {
        props.info.followTotal = props.info.followTotal === 0 ? 0 : props.info.followTotal - 1;
        MessagePlugin.warning('取消关注');
      }
    } catch {}
  }
};

//获取账号项目
const selectInit = async () => {
  try {
    let res = await projectLists(props.info.id);
    if (res.data.length > 0) {
      selectInitList.value = res.data;
      visibleStep.value = true;
      console.log(selectInitList.value);
    } else MessagePlugin.warning('暂无可添加的展览');
  } catch (err) {
    console.log(err);
  }
};
const setCurrent = (index: number) => {
  current.value = index;
  let scrollContainer = doot.value;
  const element = document.getElementById('dot-parents' + index);
  const rect = element.getBoundingClientRect();
  const containerRect = scrollContainer.getBoundingClientRect();
  const offsetleft = index > 2 ? rect.width * index - rect.width : 0; //rect.left - containerRect.left + scrollContainer.scrollLeft;

  // 设置滚动容器的scrollTop
  scrollContainer.scrollLeft = offsetleft;
  // dot-parents
};
// 添加到展览
const addId = () => {
  let token = getHeardToken();
  if (!token) {
    // ElMessageBox.alert('是否前往登录？', '您暂未登录', {
    //   confirmButtonText: '确定',
    //   callback: (action: Action) => {
    //     if (action === 'confirm') {
    //       pathSubmitClick();
    //     }
    //   },
    // });
    // visibleMessage.value = true;
    store.loginModeShow = true;
    return;
  }
  // selectInit();
  emits('addExId');
};

const closetables = (context?: any): void => {
  visibleStep.value = false;
};

//添加项目
const okStep = async () => {
  try {
    if (loading.value) {
      return;
    }
    if (projectId.value) {
      loading.value = true;
      let res = await addExhibits(projectId.value, props.info.id, [props.info.id]);
      if (res.succeeded) {
        MessagePlugin.success('添加成功');
      }

      loading.value = false;
      visibleStep.value = false;
      projectId.value = null;
    } else {
      MessagePlugin.success('请选择展览');
      return;
    }
  } catch {
    loading.value = false;
  }
};

//取消
const closeClick = () => {
  visibleMessage.value = false;
};
//确认登录
const pathSubmitClick = () => {
  visibleMessage.value = false;
  let url = window.location.href;
  let redirectUrl = 'http://wz.wuzhan.art/#/login?redirect=' + url;
  window.location.href = redirectUrl;
};

const open3DUrl = () => {
  if (!props.info.externalUrl) return;
  window.open(props.info.externalUrl);
};

// 鼠标横向滚动事件
const handlWheel = (event: any) => {
  const delta = event.wheelDelta || -event.detail;
  doot.value.scrollLeft -= delta;
  event.preventDefault();
};

watch(
  () => props.info,
  () => {
    current.value = 0;
  },
);
</script> 

<style scoped lang="less">
.exhibit-top {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  overflow: hidden;
  min-height: 460px;
  // max-height: 490px;
  .ex-img-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 460px;
    height: 460px;
  }
  .ex-img-parent {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 460px;
    height: 460px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    .ex-img {
      width: 442px;
      height: 442px;
      // border: 1px solid #5b5b5b;
      // box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
    }
  }

  .ex-img {
    position: relative;
    overflow: hidden;

    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    .cover {
      width: 100%;
      height: 100%;
      object-fit: contain;
      overflow: hidden;
      transition: all 0.3s;
      background: rgba(57, 56, 54, 0.14);
    }
  }
  .ex-img:hover {
    .cover {
      transform: scale(1.2);
    }
  }
  .Icon3d {
    position: absolute;
    top: 7px;
    right: 20px;
    display: flex;
    z-index: 20;

    img {
      width: 40px;
      height: 41.72px;
      object-fit: contain;
    }
  }
  .exhibhts-desc {
    // width: 100%;
    flex: 1;
    // min-height: 100%;
    // max-height: 490px;
    margin-left: 40px;
    display: flex;
    flex-direction: column;

    .exhibits-parameter {
      width: 100%;
      display: flex;
      flex-direction: column;
      .right-heard {
        display: flex;
        align-items: center;
        width: 129px;
        height: 34px;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        font-family: SJxingkai-C;
        font-size: 20px;
        font-weight: 400;
        line-height: 30px;
        padding-left: 24px;
        color: rgba(57, 56, 54, 1);
      }
      .parameter-item {
        margin-top: 16px;
        line-height: 32px;
        display: flex;
        .parameter-key {
          font-family: PingFangSC, PingFang SC Microsoft YaHei;
          font-weight: 400;
          font-size: 15px;
          color: rgba(57, 56, 54, 0.6);
          line-height: 32px;
          text-align: left;
          width: 80px;
        }
        .parameter-name {
          flex: 1;
          font-family: PingFangSC, PingFang SC Microsoft YaHei;
          font-size: 17px;
          color: rgba(57, 56, 54, 0.8);
          line-height: 32px;
          span {
            font-family: 'Microsoft YaHei' !important;
          }
        }
        .doot-anim {
          &:hover {
            justify-content: center !important;
          }
        }

        .item-mg {
          margin-left: 0;
        }
      }
      .parameter-item-top {
        margin-top: 16px !important;
      }
    }

    .btn {
      width: 100%;
      height: 74px;
      display: flex;
      align-items: center;
      // justify-content: space-between;
      margin-top: 16px;
      .myPostattention {
        width: 36px;
        height: 56px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-content: center;
        color: rgba(57, 56, 54, 1);
        cursor: pointer;
        margin-right: 33px;
        .iconfonts {
          display: flex;
          justify-content: center;
          font-size: 16px;

          line-height: 24px;
        }
        .myPostattention-text {
          width: 34px;
          text-align: center;
          font-family: PingFang SC;
          font-size: 14px;
          font-weight: 400;
          line-height: 32px;
          color: rgba(57, 56, 54, 1);
        }
      }
      .add-exhibition {
        position: relative;
        width: 233px;
        height: 74px;
        color: rgba(239, 237, 233, 1);
        font-family: 'PingFang SC';
        font-size: 16px;
        line-height: 22px;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        .iconfonts {
          margin-right: 6px;
          font-size: 16px;
          line-height: 22px;
        }
      }
    }
  }
}

.doot-parent {
  position: absolute;
  bottom: 37px;
  left: 85px;
  z-index: 20;
  width: 288px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;

  .doot-box {
    display: flex;
    align-items: flex-end;
    width: auto;
    overflow: auto;
    scrollbar-width: none;
    &::-webkit-scrollbar {
      display: none;
    }
    .dot-parents {
      width: 12px;
      height: 13px;
      border-radius: 100%;
      transition: all 0.3s;
      background: url(https://static.jiyi.show/free/style10/exdot.png) no-repeat center/100% 100%;
      margin-left: 12px;
      flex-shrink: 0;
      opacity: 0.5;
      &:first-child {
        margin-left: 0;
      }
    }
    &:hover .dot-parents {
      width: 60px;
      height: 60px;
      border: 1px solid rgba(236, 235, 231, 1);
      border-radius: 3px;
      .doot-item {
        opacity: 1;
      }
    }
  }
  .dot-parents-warp {
    width: 60px !important;
    height: 60px !important;
    border: 1px solid rgba(236, 235, 231, 1);
    border-radius: 3px !important;
    .doot-item {
      opacity: 1 !important;
    }
  }
  .doot-anim {
    justify-content: center;
  }
  .dot-content {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    // margin-left: 12px;
    overflow: hidden;
    cursor: pointer;
    border-radius: 3px;
    .doot-item {
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
      opacity: 0;
      transition: all 0.3s;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  // .dot-1 {
  //   margin-left: 0px;
  // }
  .dot-parents-active {
    opacity: 1 !important;
  }
  .shadown {
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.2);
    span {
      font-family: PingFang SC;
      font-size: 15px;
      line-height: 32px;
      text-align: center;
      color: rgba(236, 235, 231, 1);
    }
  }
  .doot-item-active {
    .shadown {
      opacity: 1;
    }
  }
  .doot-item:hover {
    .shadown {
      opacity: 1;
    }
  }
}

:deep(.t-dialog__body) {
  all: unset !important;
}
:deep(.t-dialog__header) {
  height: unset !important;
  all: unset !important;
  display: flex !important;
  margin-bottom: 15px !important;
}
:deep(.t-dialog__footer) {
  height: auto !important;
  all: unset !important;
  border: inherit !important;
  display: flex !important;
  justify-content: flex-end !important;
  margin-top: 15px !important;
}
:deep(.t-dialog) {
  background: #fff !important;
  padding: 20px !important;
  border-radius: 4px;
}
</style>
